# setting_tab.pl
# function for tabform

# load modules
require "./electric_bulletin_board-lib.pl";
require "./config.pl";


# setting_tab()
# setting tab generate functions
sub setting_tab() {
	# configure form start
	print &ui_form_start("index.cgi", "get");
	
	# tab name
	print &ui_hidden("tab", "setting");
	
	# read config file
	my %config_file = ();
	&read_file("$module_config_file", \%config_file);
	
	# select connect port
	print "<h4>$text{'setting_portname_title'}</h4>";
	$PortName_ref = &search_serialport("name", 1);
	print &ui_select("portname", $config_file{'portname'} || @$PortName_ref[0], $PortName_ref); 
	print &item_br(2);
	
	# select port speed
	print "<h4>$text{'setting_portspeed_title'}</h4>";
	print &ui_select("portspeed", $config_file{'portspeed'} || $DefaultPortSpeed, \@PortSpeed); 
	
	# run button
	print &item_hr();
	print &ui_submit($text{'setting_submit'});
	
	# configure form end
	print &ui_form_end();
}

# setting_run()
# setting run functions
sub setting_run() {
	# set connect port
	if ($in{'portname'} ne "") {
		$config{'portname'} = $in{'portname'};
	}
	
	# set port speed
	if ($in{'portspeed'} ne "") {
		for (my $i = 0; $i < @PortSpeed; $i++) {
			if ($PortSpeed[$i] eq $in{'portspeed'}) {
				$config{'portspeed'} = $in{'portspeed'};
				last;
			}
		}
	}
	
	# write config file
	if ($in{'portname'} ne "" || $in{'portspeed'} ne "") {
		&write_file("$module_config_file", \%config);
		print "<br>\n";
		print "設定が完了しました";
	}
	
	return;
}

